package BehaviorModel.iterorModel;

import java.util.Iterator;

/**
 * 功能描述: 计算机系迭代器
 * 2024/05/08
 *
 * @see Iterator
 * ZhangYi
 */
public class ComputerIteror implements Iterator {

    private Department[] departments;

    private int index = 0;

    public ComputerIteror(Department[] departments) {
        this.departments = departments;
        this.index = 0;
    }

    public void setDepartments(Department[] departments) {
        this.departments = departments;
        this.index=0;//// 重置游标索引
    }

    @Override
    public boolean hasNext() {
        if (index + 1 > departments.length || departments[index] == null) {
            return false;
        }
        return true;
    }

    @Override
    public Object next() {
        if (hasNext()) {
            return departments[index++];
        }
        return null;
    }

    /**
     * 功能描述: remove 目前空实现
     */
    @Override
    public void remove() {

    }
}
